// pages/detail/detail.js
import { getdetail,unlimit ,shopping,getaddfav,getfavcheck,getfavdelete} from "../../utils/http"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pics2: [],
    content: [],
    basicInfo: [],
    show: false,
    showewm:false,
    skuList:[],
    properties:[],
    number:[],
    showsc:"未收藏"
  },
  async unlimit(){
    const _this=this;
    unlimit({
      scene:wx.getStorageSync('uid'),
      expireHours:1,
    }).then(res=>{
      console.log(res);
      if(res.code!=0){
        wx.showToast({
          title: ews.msg,
          icon:"none"
        })
        return;
      }
      this.setData({
        showewm:true,
        erm:res.data,
      })
    })
  },
  onClickHide() {
    this.setData({ showewm: false });
  },
  // 添加收藏
  collect(e){
    console.log(e);
    let type=e.currentTarget.dataset.type
    let id=e.currentTarget.dataset.id
    getaddfav({type:type,goodsId:id,token:wx.getStorageSync('token')}).then(res=>{
     console.log(res);
    })
    getfavcheck({type:type,goodsId:id,token:wx.getStorageSync('token')}).then(res=>{
      console.log(res);
      this.setData({
        showsc:res.data
      })
    })
  },
  //删除收藏
  uncollect(e){
    console.log(e);
    let type=e.currentTarget.dataset.type
    let id=e.currentTarget.dataset.id
    getfavdelete({type:type,goodsId:id,token:wx.getStorageSync('token')}).then(res=>{
     console.log(res);
    })
    getfavcheck({type:type,goodsId:id,token:wx.getStorageSync('token')}).then(res=>{
      console.log(res);
      this.setData({
        showsc:res.data
      })
    })
  },
  // 加入购物车
  join(e) {
    let id = e.currentTarget.dataset.id
    console.log(id);
    shopping({
      goodsId: id,
      number: 1,
      token: wx.getStorageSync('token')
    }).then(res => {
      console.log(res);
      this.setData({
        number:res.data.number
      })
    })
  },
  // 遮罩层
  addgwc() {
    console.log("111");
    this.setData({
      show: true
    })
  },
  showPopup() {
    this.setData({ show: true });
  },
  onClose() {
    this.setData({ show: false });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // console.log(options);
    let id = options.id;
    getdetail({ id: id }).then(res => {
      console.log(res);
      this.setData({
        pics2: res.data.pics2,
        content: res.data.content,
        basicInfo: res.data.basicInfo,
        skuList:res.data.skuList,
        properties:res.data.properties
      })
      console.log(this.data.basicInfo);
      getfavcheck({type:this.data.basicInfo.type,goodsId:this.data.basicInfo.id,token:wx.getStorageSync('token')}).then(res=>{
        console.log(res);
        this.setData({
          showsc:res.data
        })
      })
    })
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})